package com.drcoffee.drcoffeemall.util;

import com.drcoffee.drcoffeemall.entry.User;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class PriceUtil {

    /* 价格字段 */
    /* 获取价格类型字段 */
    public static String getPriceType(String another, Integer permission_id) {
        String price_type = "";
        if (permission_id == 0 || permission_id == 3) {
            // 0 零售 price
            price_type = another + ".price";
        } else if (permission_id == 1) {
            // 1 内销 dealer_price
            price_type = another + ".dealer_price as price";
        } else if (permission_id == 2) {
            // 2 外销 overseas_price
            price_type = another + ".overseas_price as price";
        }
        return price_type;
    }


    /* 计算折后价格 */
    public static BigDecimal calculateDiscountedPrice(BigDecimal originalPrice, BigDecimal discountRate) {
        BigDecimal discountAmount = originalPrice.multiply(discountRate);
        return originalPrice.subtract(discountAmount).setScale(2, RoundingMode.HALF_UP);
    }
}
